/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package ve.com.fitsoft.eicb.encuesta.SB.service.persistence;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.security.permission.InlineSQLHelperUtil;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import ve.com.fitsoft.eicb.encuesta.SB.NoSuchPreguntaException;
import ve.com.fitsoft.eicb.encuesta.SB.model.Pregunta;
import ve.com.fitsoft.eicb.encuesta.SB.model.impl.PreguntaImpl;
import ve.com.fitsoft.eicb.encuesta.SB.model.impl.PreguntaModelImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the pregunta service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author leo
 * @see PreguntaPersistence
 * @see PreguntaUtil
 * @generated
 */
public class PreguntaPersistenceImpl extends BasePersistenceImpl<Pregunta>
	implements PreguntaPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link PreguntaUtil} to access the pregunta persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = PreguntaImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ENCUESTA = new FinderPath(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
			PreguntaModelImpl.FINDER_CACHE_ENABLED, PreguntaImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByencuesta",
			new String[] {
				Long.class.getName(), Long.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENCUESTA =
		new FinderPath(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
			PreguntaModelImpl.FINDER_CACHE_ENABLED, PreguntaImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByencuesta",
			new String[] { Long.class.getName(), Long.class.getName() },
			PreguntaModelImpl.GROUPID_COLUMN_BITMASK |
			PreguntaModelImpl.IDENCUESTA_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_ENCUESTA = new FinderPath(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
			PreguntaModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByencuesta",
			new String[] { Long.class.getName(), Long.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
			PreguntaModelImpl.FINDER_CACHE_ENABLED, PreguntaImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
			PreguntaModelImpl.FINDER_CACHE_ENABLED, PreguntaImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
			PreguntaModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the pregunta in the entity cache if it is enabled.
	 *
	 * @param pregunta the pregunta
	 */
	public void cacheResult(Pregunta pregunta) {
		EntityCacheUtil.putResult(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
			PreguntaImpl.class, pregunta.getPrimaryKey(), pregunta);

		pregunta.resetOriginalValues();
	}

	/**
	 * Caches the preguntas in the entity cache if it is enabled.
	 *
	 * @param preguntas the preguntas
	 */
	public void cacheResult(List<Pregunta> preguntas) {
		for (Pregunta pregunta : preguntas) {
			if (EntityCacheUtil.getResult(
						PreguntaModelImpl.ENTITY_CACHE_ENABLED,
						PreguntaImpl.class, pregunta.getPrimaryKey()) == null) {
				cacheResult(pregunta);
			}
			else {
				pregunta.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all preguntas.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(PreguntaImpl.class.getName());
		}

		EntityCacheUtil.clearCache(PreguntaImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the pregunta.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(Pregunta pregunta) {
		EntityCacheUtil.removeResult(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
			PreguntaImpl.class, pregunta.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@Override
	public void clearCache(List<Pregunta> preguntas) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (Pregunta pregunta : preguntas) {
			EntityCacheUtil.removeResult(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
				PreguntaImpl.class, pregunta.getPrimaryKey());
		}
	}

	/**
	 * Creates a new pregunta with the primary key. Does not add the pregunta to the database.
	 *
	 * @param idPregunta the primary key for the new pregunta
	 * @return the new pregunta
	 */
	public Pregunta create(long idPregunta) {
		Pregunta pregunta = new PreguntaImpl();

		pregunta.setNew(true);
		pregunta.setPrimaryKey(idPregunta);

		return pregunta;
	}

	/**
	 * Removes the pregunta with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param idPregunta the primary key of the pregunta
	 * @return the pregunta that was removed
	 * @throws ve.com.fitsoft.eicb.encuesta.SB.NoSuchPreguntaException if a pregunta with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Pregunta remove(long idPregunta)
		throws NoSuchPreguntaException, SystemException {
		return remove(Long.valueOf(idPregunta));
	}

	/**
	 * Removes the pregunta with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the pregunta
	 * @return the pregunta that was removed
	 * @throws ve.com.fitsoft.eicb.encuesta.SB.NoSuchPreguntaException if a pregunta with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Pregunta remove(Serializable primaryKey)
		throws NoSuchPreguntaException, SystemException {
		Session session = null;

		try {
			session = openSession();

			Pregunta pregunta = (Pregunta)session.get(PreguntaImpl.class,
					primaryKey);

			if (pregunta == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchPreguntaException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(pregunta);
		}
		catch (NoSuchPreguntaException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected Pregunta removeImpl(Pregunta pregunta) throws SystemException {
		pregunta = toUnwrappedModel(pregunta);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, pregunta);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(pregunta);

		return pregunta;
	}

	@Override
	public Pregunta updateImpl(
		ve.com.fitsoft.eicb.encuesta.SB.model.Pregunta pregunta, boolean merge)
		throws SystemException {
		pregunta = toUnwrappedModel(pregunta);

		boolean isNew = pregunta.isNew();

		PreguntaModelImpl preguntaModelImpl = (PreguntaModelImpl)pregunta;

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, pregunta, merge);

			pregunta.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew || !PreguntaModelImpl.COLUMN_BITMASK_ENABLED) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		else {
			if ((preguntaModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENCUESTA.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(preguntaModelImpl.getOriginalGroupId()),
						Long.valueOf(preguntaModelImpl.getOriginalIdEncuesta())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENCUESTA, args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENCUESTA,
					args);

				args = new Object[] {
						Long.valueOf(preguntaModelImpl.getGroupId()),
						Long.valueOf(preguntaModelImpl.getIdEncuesta())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENCUESTA, args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENCUESTA,
					args);
			}
		}

		EntityCacheUtil.putResult(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
			PreguntaImpl.class, pregunta.getPrimaryKey(), pregunta);

		return pregunta;
	}

	protected Pregunta toUnwrappedModel(Pregunta pregunta) {
		if (pregunta instanceof PreguntaImpl) {
			return pregunta;
		}

		PreguntaImpl preguntaImpl = new PreguntaImpl();

		preguntaImpl.setNew(pregunta.isNew());
		preguntaImpl.setPrimaryKey(pregunta.getPrimaryKey());

		preguntaImpl.setIdPregunta(pregunta.getIdPregunta());
		preguntaImpl.setIdEncuesta(pregunta.getIdEncuesta());
		preguntaImpl.setPregunta(pregunta.getPregunta());
		preguntaImpl.setTipo(pregunta.getTipo());
		preguntaImpl.setOpciones(pregunta.getOpciones());
		preguntaImpl.setCompanyId(pregunta.getCompanyId());
		preguntaImpl.setGroupId(pregunta.getGroupId());

		return preguntaImpl;
	}

	/**
	 * Returns the pregunta with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the pregunta
	 * @return the pregunta
	 * @throws com.liferay.portal.NoSuchModelException if a pregunta with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Pregunta findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the pregunta with the primary key or throws a {@link ve.com.fitsoft.eicb.encuesta.SB.NoSuchPreguntaException} if it could not be found.
	 *
	 * @param idPregunta the primary key of the pregunta
	 * @return the pregunta
	 * @throws ve.com.fitsoft.eicb.encuesta.SB.NoSuchPreguntaException if a pregunta with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Pregunta findByPrimaryKey(long idPregunta)
		throws NoSuchPreguntaException, SystemException {
		Pregunta pregunta = fetchByPrimaryKey(idPregunta);

		if (pregunta == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + idPregunta);
			}

			throw new NoSuchPreguntaException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				idPregunta);
		}

		return pregunta;
	}

	/**
	 * Returns the pregunta with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the pregunta
	 * @return the pregunta, or <code>null</code> if a pregunta with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Pregunta fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the pregunta with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param idPregunta the primary key of the pregunta
	 * @return the pregunta, or <code>null</code> if a pregunta with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Pregunta fetchByPrimaryKey(long idPregunta)
		throws SystemException {
		Pregunta pregunta = (Pregunta)EntityCacheUtil.getResult(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
				PreguntaImpl.class, idPregunta);

		if (pregunta == _nullPregunta) {
			return null;
		}

		if (pregunta == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				pregunta = (Pregunta)session.get(PreguntaImpl.class,
						Long.valueOf(idPregunta));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (pregunta != null) {
					cacheResult(pregunta);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(PreguntaModelImpl.ENTITY_CACHE_ENABLED,
						PreguntaImpl.class, idPregunta, _nullPregunta);
				}

				closeSession(session);
			}
		}

		return pregunta;
	}

	/**
	 * Returns all the preguntas where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @return the matching preguntas
	 * @throws SystemException if a system exception occurred
	 */
	public List<Pregunta> findByencuesta(long groupId, long idEncuesta)
		throws SystemException {
		return findByencuesta(groupId, idEncuesta, QueryUtil.ALL_POS,
			QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the preguntas where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @param start the lower bound of the range of preguntas
	 * @param end the upper bound of the range of preguntas (not inclusive)
	 * @return the range of matching preguntas
	 * @throws SystemException if a system exception occurred
	 */
	public List<Pregunta> findByencuesta(long groupId, long idEncuesta,
		int start, int end) throws SystemException {
		return findByencuesta(groupId, idEncuesta, start, end, null);
	}

	/**
	 * Returns an ordered range of all the preguntas where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @param start the lower bound of the range of preguntas
	 * @param end the upper bound of the range of preguntas (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching preguntas
	 * @throws SystemException if a system exception occurred
	 */
	public List<Pregunta> findByencuesta(long groupId, long idEncuesta,
		int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENCUESTA;
			finderArgs = new Object[] { groupId, idEncuesta };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ENCUESTA;
			finderArgs = new Object[] {
					groupId, idEncuesta,
					
					start, end, orderByComparator
				};
		}

		List<Pregunta> list = (List<Pregunta>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if ((list != null) && !list.isEmpty()) {
			for (Pregunta pregunta : list) {
				if ((groupId != pregunta.getGroupId()) ||
						(idEncuesta != pregunta.getIdEncuesta())) {
					list = null;

					break;
				}
			}
		}

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(4 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(3);
			}

			query.append(_SQL_SELECT_PREGUNTA_WHERE);

			query.append(_FINDER_COLUMN_ENCUESTA_GROUPID_2);

			query.append(_FINDER_COLUMN_ENCUESTA_IDENCUESTA_2);

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(groupId);

				qPos.add(idEncuesta);

				list = (List<Pregunta>)QueryUtil.list(q, getDialect(), start,
						end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first pregunta in the ordered set where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching pregunta
	 * @throws ve.com.fitsoft.eicb.encuesta.SB.NoSuchPreguntaException if a matching pregunta could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Pregunta findByencuesta_First(long groupId, long idEncuesta,
		OrderByComparator orderByComparator)
		throws NoSuchPreguntaException, SystemException {
		Pregunta pregunta = fetchByencuesta_First(groupId, idEncuesta,
				orderByComparator);

		if (pregunta != null) {
			return pregunta;
		}

		StringBundler msg = new StringBundler(6);

		msg.append(_NO_SUCH_ENTITY_WITH_KEY);

		msg.append("groupId=");
		msg.append(groupId);

		msg.append(", idEncuesta=");
		msg.append(idEncuesta);

		msg.append(StringPool.CLOSE_CURLY_BRACE);

		throw new NoSuchPreguntaException(msg.toString());
	}

	/**
	 * Returns the first pregunta in the ordered set where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching pregunta, or <code>null</code> if a matching pregunta could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Pregunta fetchByencuesta_First(long groupId, long idEncuesta,
		OrderByComparator orderByComparator) throws SystemException {
		List<Pregunta> list = findByencuesta(groupId, idEncuesta, 0, 1,
				orderByComparator);

		if (!list.isEmpty()) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * Returns the last pregunta in the ordered set where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching pregunta
	 * @throws ve.com.fitsoft.eicb.encuesta.SB.NoSuchPreguntaException if a matching pregunta could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Pregunta findByencuesta_Last(long groupId, long idEncuesta,
		OrderByComparator orderByComparator)
		throws NoSuchPreguntaException, SystemException {
		Pregunta pregunta = fetchByencuesta_Last(groupId, idEncuesta,
				orderByComparator);

		if (pregunta != null) {
			return pregunta;
		}

		StringBundler msg = new StringBundler(6);

		msg.append(_NO_SUCH_ENTITY_WITH_KEY);

		msg.append("groupId=");
		msg.append(groupId);

		msg.append(", idEncuesta=");
		msg.append(idEncuesta);

		msg.append(StringPool.CLOSE_CURLY_BRACE);

		throw new NoSuchPreguntaException(msg.toString());
	}

	/**
	 * Returns the last pregunta in the ordered set where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching pregunta, or <code>null</code> if a matching pregunta could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Pregunta fetchByencuesta_Last(long groupId, long idEncuesta,
		OrderByComparator orderByComparator) throws SystemException {
		int count = countByencuesta(groupId, idEncuesta);

		List<Pregunta> list = findByencuesta(groupId, idEncuesta, count - 1,
				count, orderByComparator);

		if (!list.isEmpty()) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * Returns the preguntas before and after the current pregunta in the ordered set where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * @param idPregunta the primary key of the current pregunta
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next pregunta
	 * @throws ve.com.fitsoft.eicb.encuesta.SB.NoSuchPreguntaException if a pregunta with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Pregunta[] findByencuesta_PrevAndNext(long idPregunta, long groupId,
		long idEncuesta, OrderByComparator orderByComparator)
		throws NoSuchPreguntaException, SystemException {
		Pregunta pregunta = findByPrimaryKey(idPregunta);

		Session session = null;

		try {
			session = openSession();

			Pregunta[] array = new PreguntaImpl[3];

			array[0] = getByencuesta_PrevAndNext(session, pregunta, groupId,
					idEncuesta, orderByComparator, true);

			array[1] = pregunta;

			array[2] = getByencuesta_PrevAndNext(session, pregunta, groupId,
					idEncuesta, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected Pregunta getByencuesta_PrevAndNext(Session session,
		Pregunta pregunta, long groupId, long idEncuesta,
		OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_PREGUNTA_WHERE);

		query.append(_FINDER_COLUMN_ENCUESTA_GROUPID_2);

		query.append(_FINDER_COLUMN_ENCUESTA_IDENCUESTA_2);

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		qPos.add(groupId);

		qPos.add(idEncuesta);

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(pregunta);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<Pregunta> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the preguntas that the user has permission to view where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @return the matching preguntas that the user has permission to view
	 * @throws SystemException if a system exception occurred
	 */
	public List<Pregunta> filterFindByencuesta(long groupId, long idEncuesta)
		throws SystemException {
		return filterFindByencuesta(groupId, idEncuesta, QueryUtil.ALL_POS,
			QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the preguntas that the user has permission to view where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @param start the lower bound of the range of preguntas
	 * @param end the upper bound of the range of preguntas (not inclusive)
	 * @return the range of matching preguntas that the user has permission to view
	 * @throws SystemException if a system exception occurred
	 */
	public List<Pregunta> filterFindByencuesta(long groupId, long idEncuesta,
		int start, int end) throws SystemException {
		return filterFindByencuesta(groupId, idEncuesta, start, end, null);
	}

	/**
	 * Returns an ordered range of all the preguntas that the user has permissions to view where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @param start the lower bound of the range of preguntas
	 * @param end the upper bound of the range of preguntas (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching preguntas that the user has permission to view
	 * @throws SystemException if a system exception occurred
	 */
	public List<Pregunta> filterFindByencuesta(long groupId, long idEncuesta,
		int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		if (!InlineSQLHelperUtil.isEnabled(groupId)) {
			return findByencuesta(groupId, idEncuesta, start, end,
				orderByComparator);
		}

		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(4 +
					(orderByComparator.getOrderByFields().length * 3));
		}
		else {
			query = new StringBundler(3);
		}

		if (getDB().isSupportsInlineDistinct()) {
			query.append(_FILTER_SQL_SELECT_PREGUNTA_WHERE);
		}
		else {
			query.append(_FILTER_SQL_SELECT_PREGUNTA_NO_INLINE_DISTINCT_WHERE_1);
		}

		query.append(_FINDER_COLUMN_ENCUESTA_GROUPID_2);

		query.append(_FINDER_COLUMN_ENCUESTA_IDENCUESTA_2);

		if (!getDB().isSupportsInlineDistinct()) {
			query.append(_FILTER_SQL_SELECT_PREGUNTA_NO_INLINE_DISTINCT_WHERE_2);
		}

		if (orderByComparator != null) {
			if (getDB().isSupportsInlineDistinct()) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}
			else {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
					orderByComparator);
			}
		}

		String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
				Pregunta.class.getName(),
				_FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);

		Session session = null;

		try {
			session = openSession();

			SQLQuery q = session.createSQLQuery(sql);

			if (getDB().isSupportsInlineDistinct()) {
				q.addEntity(_FILTER_ENTITY_ALIAS, PreguntaImpl.class);
			}
			else {
				q.addEntity(_FILTER_ENTITY_TABLE, PreguntaImpl.class);
			}

			QueryPos qPos = QueryPos.getInstance(q);

			qPos.add(groupId);

			qPos.add(idEncuesta);

			return (List<Pregunta>)QueryUtil.list(q, getDialect(), start, end);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	/**
	 * Returns the preguntas before and after the current pregunta in the ordered set of preguntas that the user has permission to view where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * @param idPregunta the primary key of the current pregunta
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next pregunta
	 * @throws ve.com.fitsoft.eicb.encuesta.SB.NoSuchPreguntaException if a pregunta with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Pregunta[] filterFindByencuesta_PrevAndNext(long idPregunta,
		long groupId, long idEncuesta, OrderByComparator orderByComparator)
		throws NoSuchPreguntaException, SystemException {
		if (!InlineSQLHelperUtil.isEnabled(groupId)) {
			return findByencuesta_PrevAndNext(idPregunta, groupId, idEncuesta,
				orderByComparator);
		}

		Pregunta pregunta = findByPrimaryKey(idPregunta);

		Session session = null;

		try {
			session = openSession();

			Pregunta[] array = new PreguntaImpl[3];

			array[0] = filterGetByencuesta_PrevAndNext(session, pregunta,
					groupId, idEncuesta, orderByComparator, true);

			array[1] = pregunta;

			array[2] = filterGetByencuesta_PrevAndNext(session, pregunta,
					groupId, idEncuesta, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected Pregunta filterGetByencuesta_PrevAndNext(Session session,
		Pregunta pregunta, long groupId, long idEncuesta,
		OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		if (getDB().isSupportsInlineDistinct()) {
			query.append(_FILTER_SQL_SELECT_PREGUNTA_WHERE);
		}
		else {
			query.append(_FILTER_SQL_SELECT_PREGUNTA_NO_INLINE_DISTINCT_WHERE_1);
		}

		query.append(_FINDER_COLUMN_ENCUESTA_GROUPID_2);

		query.append(_FINDER_COLUMN_ENCUESTA_IDENCUESTA_2);

		if (!getDB().isSupportsInlineDistinct()) {
			query.append(_FILTER_SQL_SELECT_PREGUNTA_NO_INLINE_DISTINCT_WHERE_2);
		}

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				if (getDB().isSupportsInlineDistinct()) {
					query.append(_ORDER_BY_ENTITY_ALIAS);
				}
				else {
					query.append(_ORDER_BY_ENTITY_TABLE);
				}

				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				if (getDB().isSupportsInlineDistinct()) {
					query.append(_ORDER_BY_ENTITY_ALIAS);
				}
				else {
					query.append(_ORDER_BY_ENTITY_TABLE);
				}

				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
				Pregunta.class.getName(),
				_FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);

		SQLQuery q = session.createSQLQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		if (getDB().isSupportsInlineDistinct()) {
			q.addEntity(_FILTER_ENTITY_ALIAS, PreguntaImpl.class);
		}
		else {
			q.addEntity(_FILTER_ENTITY_TABLE, PreguntaImpl.class);
		}

		QueryPos qPos = QueryPos.getInstance(q);

		qPos.add(groupId);

		qPos.add(idEncuesta);

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(pregunta);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<Pregunta> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the preguntas.
	 *
	 * @return the preguntas
	 * @throws SystemException if a system exception occurred
	 */
	public List<Pregunta> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the preguntas.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of preguntas
	 * @param end the upper bound of the range of preguntas (not inclusive)
	 * @return the range of preguntas
	 * @throws SystemException if a system exception occurred
	 */
	public List<Pregunta> findAll(int start, int end) throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the preguntas.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of preguntas
	 * @param end the upper bound of the range of preguntas (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of preguntas
	 * @throws SystemException if a system exception occurred
	 */
	public List<Pregunta> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<Pregunta> list = (List<Pregunta>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_PREGUNTA);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_PREGUNTA;
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<Pregunta>)QueryUtil.list(q, getDialect(),
							start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<Pregunta>)QueryUtil.list(q, getDialect(),
							start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes all the preguntas where groupId = &#63; and idEncuesta = &#63; from the database.
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByencuesta(long groupId, long idEncuesta)
		throws SystemException {
		for (Pregunta pregunta : findByencuesta(groupId, idEncuesta)) {
			remove(pregunta);
		}
	}

	/**
	 * Removes all the preguntas from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (Pregunta pregunta : findAll()) {
			remove(pregunta);
		}
	}

	/**
	 * Returns the number of preguntas where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @return the number of matching preguntas
	 * @throws SystemException if a system exception occurred
	 */
	public int countByencuesta(long groupId, long idEncuesta)
		throws SystemException {
		Object[] finderArgs = new Object[] { groupId, idEncuesta };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ENCUESTA,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_COUNT_PREGUNTA_WHERE);

			query.append(_FINDER_COLUMN_ENCUESTA_GROUPID_2);

			query.append(_FINDER_COLUMN_ENCUESTA_IDENCUESTA_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(groupId);

				qPos.add(idEncuesta);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ENCUESTA,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of preguntas that the user has permission to view where groupId = &#63; and idEncuesta = &#63;.
	 *
	 * @param groupId the group ID
	 * @param idEncuesta the id encuesta
	 * @return the number of matching preguntas that the user has permission to view
	 * @throws SystemException if a system exception occurred
	 */
	public int filterCountByencuesta(long groupId, long idEncuesta)
		throws SystemException {
		if (!InlineSQLHelperUtil.isEnabled(groupId)) {
			return countByencuesta(groupId, idEncuesta);
		}

		StringBundler query = new StringBundler(3);

		query.append(_FILTER_SQL_COUNT_PREGUNTA_WHERE);

		query.append(_FINDER_COLUMN_ENCUESTA_GROUPID_2);

		query.append(_FINDER_COLUMN_ENCUESTA_IDENCUESTA_2);

		String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
				Pregunta.class.getName(),
				_FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);

		Session session = null;

		try {
			session = openSession();

			SQLQuery q = session.createSQLQuery(sql);

			q.addScalar(COUNT_COLUMN_NAME,
				com.liferay.portal.kernel.dao.orm.Type.LONG);

			QueryPos qPos = QueryPos.getInstance(q);

			qPos.add(groupId);

			qPos.add(idEncuesta);

			Long count = (Long)q.uniqueResult();

			return count.intValue();
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	/**
	 * Returns the number of preguntas.
	 *
	 * @return the number of preguntas
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_PREGUNTA);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Initializes the pregunta persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.ve.com.fitsoft.eicb.encuesta.SB.model.Pregunta")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<Pregunta>> listenersList = new ArrayList<ModelListener<Pregunta>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<Pregunta>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}
	}

	public void destroy() {
		EntityCacheUtil.removeCache(PreguntaImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = EncuestaPersistence.class)
	protected EncuestaPersistence encuestaPersistence;
	@BeanReference(type = PreguntaPersistence.class)
	protected PreguntaPersistence preguntaPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	private static final String _SQL_SELECT_PREGUNTA = "SELECT pregunta FROM Pregunta pregunta";
	private static final String _SQL_SELECT_PREGUNTA_WHERE = "SELECT pregunta FROM Pregunta pregunta WHERE ";
	private static final String _SQL_COUNT_PREGUNTA = "SELECT COUNT(pregunta) FROM Pregunta pregunta";
	private static final String _SQL_COUNT_PREGUNTA_WHERE = "SELECT COUNT(pregunta) FROM Pregunta pregunta WHERE ";
	private static final String _FINDER_COLUMN_ENCUESTA_GROUPID_2 = "pregunta.groupId = ? AND ";
	private static final String _FINDER_COLUMN_ENCUESTA_IDENCUESTA_2 = "pregunta.idEncuesta = ?";
	private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "pregunta.idPregunta";
	private static final String _FILTER_SQL_SELECT_PREGUNTA_WHERE = "SELECT DISTINCT {pregunta.*} FROM encuesta_Pregunta pregunta WHERE ";
	private static final String _FILTER_SQL_SELECT_PREGUNTA_NO_INLINE_DISTINCT_WHERE_1 =
		"SELECT {encuesta_Pregunta.*} FROM (SELECT DISTINCT pregunta.idPregunta FROM encuesta_Pregunta pregunta WHERE ";
	private static final String _FILTER_SQL_SELECT_PREGUNTA_NO_INLINE_DISTINCT_WHERE_2 =
		") TEMP_TABLE INNER JOIN encuesta_Pregunta ON TEMP_TABLE.idPregunta = encuesta_Pregunta.idPregunta";
	private static final String _FILTER_SQL_COUNT_PREGUNTA_WHERE = "SELECT COUNT(DISTINCT pregunta.idPregunta) AS COUNT_VALUE FROM encuesta_Pregunta pregunta WHERE ";
	private static final String _FILTER_ENTITY_ALIAS = "pregunta";
	private static final String _FILTER_ENTITY_TABLE = "encuesta_Pregunta";
	private static final String _ORDER_BY_ENTITY_ALIAS = "pregunta.";
	private static final String _ORDER_BY_ENTITY_TABLE = "encuesta_Pregunta.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Pregunta exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Pregunta exists with the key {";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(PreguntaPersistenceImpl.class);
	private static Pregunta _nullPregunta = new PreguntaImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<Pregunta> toCacheModel() {
				return _nullPreguntaCacheModel;
			}
		};

	private static CacheModel<Pregunta> _nullPreguntaCacheModel = new CacheModel<Pregunta>() {
			public Pregunta toEntityModel() {
				return _nullPregunta;
			}
		};
}